#include <iostream>
using namespace std;

const int N = 100010;
int m, x;
string op;

class my_queue
{
private:
    int q[N];
    int hh;
    int tt;

public:
    my_queue();
    void push(int x);
    int pop();
    bool is_empty();
    int query();
};

my_queue::my_queue()
{
    tt = -1;
    hh = 0;
}

void my_queue::push(int x)
{
    q[++tt] = x;
    return;
}

int my_queue::pop()
{
    return q[hh++];
}

bool my_queue::is_empty()
{
    return tt < hh;
}

int my_queue::query()
{
    return q[hh];
}

int main()
{
    my_queue que;
    scanf("%d", &m);
    while (m--)
    {
        cin >> op;
        if (op == "push")
        {
            scanf("%d", &x);
            que.push(x);
        }
        else if (op == "pop")
            que.pop();
        else if (op == "empty")
            if (que.is_empty())
                printf("YES\n");
            else
                printf("NO\n");
        else
            printf("%d\n", que.query());
    }
    return 0;
}